package com.ybox.auth.form;

import com.ybox.common.core.constant.UserConstants;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

/**
 * 用户登录对象
 *
 * @author ych
 */
public class LoginBody {
    /**
     * 用户名
     */
    private String username;

    /**
     * 用户电话
     */
    private String phone;

    /**
     * 用户密码
     */
    private String password;

    public interface login {
    }

    public interface loginByPhone{

    }

    @NotBlank(message = "用户名不能为空")
    @Length(min = UserConstants.USERNAME_MIN_LENGTH, max = UserConstants.USERNAME_MAX_LENGTH, message = "用户名不在指定范围", groups = {RegisterBody.register.class, LoginBody.login.class})
    @Email(message = "邮箱格式错误")
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @NotBlank(message = "密码不能为空", groups = {LoginBody.login.class})
    @Length(min = UserConstants.PASSWORD_MIN_LENGTH, max = UserConstants.PASSWORD_MAX_LENGTH, message = "用户密码不在指定范围", groups = {RegisterBody.register.class, LoginBody.login.class})
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @NotBlank(message = "手机号不能为空", groups = {LoginBody.loginByPhone.class})
    @Pattern(regexp = "/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$/", message = "手机号格式错误", groups = {LoginBody.loginByPhone.class})
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}
